package org.saratogaschools.edd.firefighter.client;

import org.saratogaschools.edd.firefighter.client.resources.AegisResources;
import org.saratogaschools.edd.firefighter.shared.FireFighterService;
import org.saratogaschools.edd.firefighter.shared.FireFighterServiceAsync;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.core.client.GWT;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DeckLayoutPanel;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.SimpleEventBus;

public class ClientFactoryImpl implements ClientFactory {
	
	private ActivityManager manager;
	private ActivityMapper mapper;
	private PlaceController controller;
	private SimpleEventBus eventBus;
	private IsWidget display;
	private FireFighterServiceAsync service;
	private AegisResources resources;
	
	public ClientFactoryImpl() {
		this.resources = GWT.create(AegisResources.class);
		this.mapper = new org.saratogaschools.edd.firefighter.client.activity.ActivityMapperImpl(this);
		this.eventBus = new SimpleEventBus();
		this.manager = new ActivityManager(mapper, eventBus);
		this.controller = new PlaceController(eventBus);
		this.service = GWT.create(FireFighterService.class);
		
		DeckLayoutPanel panel = new DeckLayoutPanel();
		panel.setAnimationDuration(300);
		manager.setDisplay(panel);
		
		this.display = panel;
	}

	@Override
	public ActivityManager getActivityManager() {
		return manager;
	}

	@Override
	public PlaceController getPlaceController() {
		return controller;
	}

	@Override
	public IsWidget getDisplay() {
		return display;
	}


	@Override
	public EventBus getEventBus() {
		return eventBus;
	}
	
	@Override
	public FireFighterServiceAsync getService() {
		return this.service;
	}
	
	@Override
	public AegisResources getResources() {
		return this.resources;
	}
	
	@Override
	public boolean areAdvancedFeaturesActive() {
		String professional = Window.Location.getParameter("professional");
		if (professional != null && "true".equals(professional)) {
			return true;
		}
		else {
			return false;
		}
	}

}
